/*
Naijanimi Free SMS Application for Nokia mobiles.

"Naijanimi Free SMS Application" is protected by the copyright law
(c) 2011 Enrico Miglino / Tech Consulting (enrico.miglino@ovi.com)
Distributed under the LGPL 3.0 license.

This file is part of "Naijanimi Free SMS Application".

    "Naijanimi Free SMS Application" is free software: you can redistribute it
    and/or modify it under the terms of the Lesser GNU General Public License
    as published by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Naijanimi Free SMS Application" is distributed in the hope that it
    will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    Lesser GNU General Public License for more details.

    You should have received a copy of the Lesser GNU General Public License
    along with "Naijanimi Free SMS Application".
    If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 1.0

// Send SMS
Item {
    id: formElements

    // Configuration parameters for external settings
    property int formBorder: 10     // Unique value, for all the form elements
    property int buttonsSpacing: 1  // Spacing between buttons. Can be zero for adiacent buttons.
    property int fieldSpacing: 5   // Field spacing in pixels.
    // Top margin for the field column, relative to the form size.
    // Value needs to be calculated to save the variable form header title.
    property int fieldTopMargin: formElements.height * 0.14
    property int textHeight: 33     // Height of text labels texts in pixels.
    property int fieldHeight: 55    // Height of text fields
    property int areaHeight: formElements.height * 0.40 // Text edit area height (multiline)
    // Scaling value has effect on button width only.
    // Default value: 1 for no scaling
    // Warning: Scaling buttons loose horizontal centering.
    // ACTUALLY UNUSED (see function getButtonWidth() for more info)
    property real buttonScaling: 1
    // Note: button colors are not the names of palette color but refers to
    // the button graphic background using an image whose filename is
    // composed. For more informations see Button object source.
    property string buttonColor: "green"
    property string buttonTextOk: "Send"
    property string buttonTextClear: "Clear"

    // Preset values (should be changed when instantiated)
    width: 250
    height: 250

    // ---------------------------------------------------------- START DEBUG BLOCK
    // Debug info.
    // For debug console messages use debugMessage(msg) instead of console.log(msg)
    // in the source module set baseMsg property with the string that should appear
    // before any debug message on the console.
    // To disable debug, set debugStatus to false. This can be done also only in some
    // code blocks.
    property bool debugStatus: true
    property string baseMsg: "*** Debug FunctionSendSMS.qml: "
    function debugMessage(msg) { if (debugStatus == true) console.log(baseMsg + msg); }
    // ---------------------------------------------------------- END DEBUG BLOCK

    // Calculate the with of the buttons.
    function getButtonWidth() {
        var result;
        var numButtons = 2; // Number of buttons in the form

        // Calculate the largest possible button width, relative to the form area
        result = (formElements.width - formElements.buttonsSpacing - (formElements.formBorder * 2)) / numButtons;

//        // Check button scaling factor before applying. If value is out of range, button width is always correct
//        if ((formElements.buttonScaling < 1) && (formElements.buttonScaling > 0.05))
//            // Scale the value to reduce the button size.
//            result = result * formElements.buttonScaling;

        debugMessage("Button width = " +
                     result +
                     "\n - FormElements.width = " +
                     formElements.width +
                     "\n - FormElements.formBorder = " +
                     formElements.formBorder);
        return result;
    }

    // Choice button(s)
    Row {
        id: buttons

        spacing: formElements.buttonsSpacing
        width: formElements.width - formElements.formBorder * 2
        visible: true

        // Anchors buttons to the bottom of the screen
        anchors {
            bottom: formElements.bottom
            bottomMargin: formElements.formBorder
            left: formElements.left
            leftMargin: formElements.formBorder
        }

        Button {
            id: btnOk

            width: formElements.getButtonWidth(); height: formElements.buttonHeight
            color: formElements.buttonColor; operation: formElements.buttonTextOk
            //            onClicked: { /* Set button function */ }
        }

        Button {
            id: btnClear

            width: formElements.getButtonWidth(); height: formElements.buttonHeight
            color: formElements.buttonColor; operation: formElements.buttonTextClear
            //            onClicked: { /* Set button function */ }
        }
    }

    // Form fields
    Column {
        id: fields

        spacing: formElements.fieldSpacing
        width: parent.width * 0.84
        visible: true

        anchors {
            top: parent.top
            topMargin: formElements.fieldTopMargin
            right: formElements.right
            rightMargin: formElements.formBorder
        }

        // =========== Recipient Phone Number
        Text {
            text: "Group Name"
            font.pointSize: 10
        }

        InputField {
            id: fieldRecipe
            width: parent.width
            height: formElements.fieldHeight
        }

        // ============ Sms text message
        Text {
            text: "Message"
            font.pointSize: 10
        }

        InputArea {
            id: fieldMessage
            width: parent.width
            height: formElements.areaHeight
        }

        // ============= Send mode switch (with or without AD message)
        Row {
            id: adSelect

            spacing: formElements.buttonsSpacing
            width: formElements.width - formElements.formBorder * 2
            visible: true
            SwitchOnOff {
                id: switchAD
                scale: 0.85
            }
            Text {
                anchors.verticalCenter: switchAD.verticalCenter
                text: "Free (+AD)"
                font.pointSize: 10
            }
        }
    }
}
